<script setup lang='ts'>
import { onMounted, ref, watch } from 'vue';

const props = withDefaults(defineProps<{
    modelValue?: any,
    enumStrsList: [aliasName: any, value: any][],
    withUndefined: boolean,
    defaultValue?: any,
    readonly?: boolean
}>(), { readonly: false })

const emits = defineEmits(["update:modelValue"]);

const modelValueRef = ref<number | string | undefined>('')
const leftulisShow = ref(false)
onMounted(() => {
    modelValueRef.value = props.modelValue ?? ''
})
watch(modelValueRef, (val) => {
    emits('update:modelValue', val)
})
const changeSelect = (item: string) => {
    modelValueRef.value = item
    leftulisShow.value = false
}
</script>

<template>
    <div class="select">
        <div @click.stop.prevent="leftulisShow = !leftulisShow">{{ modelValueRef }} <span class="images_xiaosanjiao"
                :class="leftulisShow ? 'images_xiaosanjiao_transform' : ''"></span>
        </div>
        <ul v-show="leftulisShow">
            <li v-for="item in enumStrsList" @click="changeSelect(item[1])">{{ item[0] }}</li>
        </ul>
    </div>
</template>

<style scoped>
.select {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    line-height: 26px;
    color: rgba(230, 230, 230, 1);
    position: relative;
}

.select>div {
    height: 26px;
    width: 100%;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
}

.select>ul {
    position: absolute;
    z-index: 20;
    max-height: 100px;
    left: 0;
    top: 16px;
    overflow-y: auto;
    background: #292a2e;
    box-shadow: 0px 2px 6px 0px rgba(26, 26, 28, 0.68);
    border-radius: 4px;
    overflow-x: hidden;
}

.select>ul::-webkit-scrollbar {
    width: 3px;
    background-color: rgba(41, 42, 46, 1);
    border-radius: 2px;
}

.select>ul::-webkit-scrollbar-thumb {
    background-color: rgba(183, 183, 183, 1);
    border-radius: 2px;
}

.select>ul>li {
    list-style: none;
    width: 180px;
    height: 20px;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
    text-align: left;
    padding-left: 10px;
    margin-left: -40px;
    white-space: nowrap;
    color: rgba(230, 230, 230, 1);
}

.select>ul>li:hover {
    background: #37393e;
}

/* .xiaosanjiao {
    display: flex;
    align-items: center;
    justify-content: center
}

.xiaosanjiao_transform {
    transform: rotate(-90deg);
} */
</style>
